package com.kehao.leetcode.jzoffer;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class JZSolution065 {
    public int minimumLengthEncoding(String[] words) {
        List<String> list = Arrays.stream(words).sorted((s1, s2) -> s2.length() - s1.length()).collect(Collectors.toList());
        int result = 0;
        for (int i = 0; i < list.size(); i++) {
            boolean add = true;
            for (int j = 0; j < i; j++) {
                if(list.get(j).endsWith(list.get(i))){
                    add = false;
                    break;
                }
            }
            if(add){
                result+=list.get(i).length()+1;
            }
        }
        return result;
    }
}
